package com.jack.handlers;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/test")
public class MyController {
	/*@RequestMapping("/register.do")
	public ModelAndView doRegister(String name,int age) {
		System.out.println("name:"+name);
		System.out.println("age:"+age);
		ModelAndView mv=new ModelAndView();
		//底层执行的是request.setAttribute()方法
		mv.addObject("message", "hello SpringMvc World");
		mv.addObject("name", name);
		mv.addObject("age", age);
		mv.setViewName("/WEB-INF/jsp/welcome.jsp");
		return mv;
	}*/
	
	@RequestMapping("/register.do")
	public String doRegister(String name,int age) {
		System.out.println("name:"+name);
		System.out.println("age:"+age);
		
		return "redirect:su.do";
	}
	
	@RequestMapping("/su.do")
	public String su() {
		return "success";
	}
	
	@RequestMapping("/my.do")
	public String my() {
		return "welcome";
	}

	@RequestMapping("/myAjax.do")
	public void doAjax(String name,int age) {
		System.out.println("name:"+name);
		System.out.println("age:"+age);
	}
	
	@RequestMapping("/myAjax1.do")
	@ResponseBody//将返回的数据放到响应体中
	public Object doAjax1(String name,int age) {
		System.out.println("name:"+name);
		System.out.println("age:"+age);
		
		return 123.45;
	}
	
	@RequestMapping("/myAjax2.do")
	@ResponseBody//将返回的数据放到响应体中
	public Object doAjax2(String name,int age) {
		System.out.println("name:"+name);
		System.out.println("age:"+age);
		
		return new Student("lisi", 24);
	}
	
	@RequestMapping("/myAjax3.do")
	@ResponseBody//将返回的数据放到响应体中
	public Object doAjax3(String name,int age) {
		System.out.println("name:"+name);
		System.out.println("age:"+age);
		Map<String,Student> map=new HashMap<String,Student>();
		map.put("stu1", new Student("lisi", 24));
		map.put("stu2", new Student("liui", 25));
		return map;
	}
}
